package cn.itcast.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.itcast.service.ExcelExportService;
import cn.itcast.service.ReportService;
import cn.itcast.vo.BusinessExcel;
import cn.itcast.vo.BusinessReportVo;
import com.alibaba.excel.EasyExcel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ExcelExportServiceImpl implements ExcelExportService {
    @Autowired
    private ReportService reportService;
    @Override
    public List<BusinessExcel> exportExcel() {
        BusinessReportVo businessReportVo = reportService.selectBusiness();
        BusinessExcel businessExcel=new BusinessExcel();
        BeanUtil.copyProperties(businessReportVo,businessExcel);
        List<Object> name = CollUtil.getFieldValues(businessReportVo.getHotSetmeal(), "name");
        List<Object> setmealCount = CollUtil.getFieldValues(businessReportVo.getHotSetmeal(), "setmealCount");
        List<Object> proportion = CollUtil.getFieldValues(businessReportVo.getHotSetmeal(), "proportion");
        businessExcel.setName(Convert.toStr(name));
        businessExcel.setProportion(Convert.toStr(proportion));
        businessExcel.setSetmealCount(Convert.toStr(setmealCount));

        //String fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
        List<BusinessExcel> list=new ArrayList<>();
        list.add(businessExcel);

        return list;
    }
}
